package com.seecode.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.seecode.R;
import com.seecode.UnitClass.BookClass;

import java.util.List;

/**
 * Created by Administrator on 2017/10/26.
 */

public class BookAdapter extends ArrayAdapter<BookClass> {

    private int resourceId;

    public BookAdapter(Context context, int textViewResourceId,
                       List<BookClass> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
        BookClass bookClass = getItem(position); //
        View view;
        ViewHolder viewHolder;

        if(convertView==null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
            // viewHolder = new ViewHolder();
            viewHolder=new ViewHolder();


            viewHolder.fileName = (TextView) view.findViewById(R.id.book_title);

            view.setTag(viewHolder);
        }else{
            view=convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
        //viewHOlderInter 2 ele is view 2 inter element

        viewHolder.fileName.setText(bookClass.getFileName());

        return view;
    }
    class ViewHolder{


        TextView fileName;

    }
}
